package cn.htcode.controller;

import cn.htcode.service.IRegisterService;
import cn.htcode.service.imp.RegisterImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: Mr_he
 * @Version:1.0
 */
@WebServlet("/register")
public class RegisterController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account = req.getParameter("account");
        IRegisterService register = new RegisterImpl();
        boolean ret = register.checkAccount(account);
        String acc = ret ? "yes" : "no";
        resp.getWriter().print(acc);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account = req.getParameter("account");
        String password = req.getParameter("password");
        IRegisterService register = new RegisterImpl();
//        插入数据
        register.insert(account, password);
        req.getRequestDispatcher("/login.html").forward(req, resp);
    }
}
